<?php
	// You need to call this function at folder set\setting_tbl.php

	if(SETTING_CHECK_TABLES == 1)
	{
		function check_tables($val)
		{
			$number = $val;
			$result = 0;
			
			// Check Table Ms_User
			if($number == 1)
			{
				$table = "ms_user";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`userid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`username` VARCHAR( 30 ) NOT NULL ,
						`password` VARCHAR( 50 ) NULL DEFAULT NULL ,
						`usergroupid` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userstatus` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `userid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check system user at Table ms_user
				$sql = "select * from ms_user where username = 'system' and userid = '1' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_user` (
						`userid` ,
						`username` ,
						`password` ,
						`usergroupid` ,
						`userstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'1',  'system',  '5ccce774034788a99b7df0eee1e98c8x', '1', '1', '1',  '1',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check masteradmin user at Table ms_user
				$sql = "select * from ms_user where username = 'masteradmin' and userid = '2' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_user` (
						`userid` ,
						`username` ,
						`password` ,
						`usergroupid` ,
						`userstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'2',  'masteradmin',  '5ccce774034788a99b7df0eee1e98c85', '1', '1', '1',  '1',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check superadmin user at Table ms_user
				$sql = "select * from ms_user where username = 'superadmin' and userid = '3' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						
						INSERT INTO  `".DB_NAME."`.`ms_user` (
						`userid` ,
						`username` ,
						`password` ,
						`usergroupid` ,
						`userstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'3',  'superadmin',  '0d2eaad562c7ebe738e108c5b10fae96', '2', '1', '1',  '2',  '".GET_DATE."',  '',  'A'
						);
						
						
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table tr_log
			if($number == 2)
			{
				$table = "tr_log";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`logid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`logaction` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`logdate` DATETIME NULL DEFAULT NULL ,
						`userid` INT( 11 ) NULL DEFAULT NULL ,
						`logip` VARCHAR( 15 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `logid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_module
			if($number == 3)
			{
				$table = "ms_module";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`moduleid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`modulename` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulelabel` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`moduleheading` VARCHAR( 100 ) NULL DEFAULT NULL ,
						`moduleurlfront` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`moduleurlback` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`moduleposition` INT( 11 ) NULL DEFAULT NULL ,
						`modulestatus` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `moduleid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				$sql = "select * from ms_module where moduleid = 1";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module` (
						`moduleid` ,
						`modulename` ,
						`modulelabel` ,
						`moduleheading` ,
						`moduleurlfront` ,
						`moduleurlback` ,
						`moduleposition` ,
						`modulestatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'1',  'home',  'home', '',  'home', 'home.php'  , '1' , '1' , '1', '' ,   '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_module_sub
			if($number == 4)
			{
				$table = "ms_module_sub";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`modulesubid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`moduleid` INT( 11 ) NULL DEFAULT NULL ,
						`modulesubname` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulesublabel` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulesuburltype` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulesuburlfront` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`modulesuburlback` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`modulesubposition` INT( 11 ) NULL DEFAULT NULL ,
						`modulesubstatus` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `modulesubid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// check submodule record 'submodules'
				$sql = "select * from ms_module_sub where modulesubname = 'submodules'";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_sub` (
						`modulesubid` ,
						`moduleid` ,
						`modulesubname` ,
						`modulesublabel` ,
						`modulesuburltype` ,
						`modulesuburlfront` ,
						`modulesuburlback` ,
						`modulesubposition` ,
						`modulesubstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'1',  '1', 'submodules',  'sub modules',  'management',  'submodules.php',  'submodules.php',  '1',  '1',  '1',  '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// check submodule record 'usergroup'
				$sql = "select * from ms_module_sub where modulesubname = 'users'";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_sub` (
						`modulesubid` ,
						`moduleid` ,
						`modulesubname` ,
						`modulesublabel` ,
						`modulesuburltype` ,
						`modulesuburlfront` ,
						`modulesuburlback` ,
						`modulesubposition` ,
						`modulesubstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'2',  '2',  'users',  'users',  'management',  'users.php',  'users.php',  '1',  '1',  '1',  '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				/*
				// check submodule record 'moduleprivilege'
				$sql = "select * from ms_module_sub where modulesubname = 'moduleprivilege'";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_sub` (
						`modulesubid` ,
						`moduleid` ,
						`modulesubname` ,
						`modulesublabel` ,
						`modulesuburltype` ,
						`modulesuburlfront` ,
						`modulesuburlback` ,
						`modulesubposition` ,
						`modulesubstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'3',  '1',  'moduleprivilege',  'module privilege',  'management',  'moduleprivilege.php',  'moduleprivilege.php',  '2',  '1',  '1',  '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				*/
				
				/*
				// check submodule record 'submodules 2'
				$sql = "select * from ms_module_sub where modulesubname = 'submodules 2'";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_sub` (
						`modulesubid` ,
						`moduleid` ,
						`modulesubname` ,
						`modulesublabel` ,
						`modulesuburltype` ,
						`modulesuburlfront` ,
						`modulesuburlback` ,
						`modulesubposition` ,
						`modulesubstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'4',  '1',  'submodules 2',  'sub modules 2',  'management',  'submodules2.php',  'submodules2.php',  '1',  '1',  '1',  '',  '".GET_DATE."',  '',  'D'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
					
				}
				*/
			}
			
			// Check Table ms_setting
			if($number == 5)
			{
				$table = "ms_setting";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`settingid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`settingvalue` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`settingname` VARCHAR( 50 ) NULL DEFAULT NULL ,
						`settingmodule` VARCHAR( 50 ) NULL DEFAULT NULL ,
						`settingdesc` VARCHAR( 100 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `settingid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_status
			if($number == 6)
			{
				$table = "ms_status";
				if(!(table_exists($table, DB_NAME)))	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`statusid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`statusvalue` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`statusname` VARCHAR( 50 ) NULL DEFAULT NULL ,
						`statusmodule` VARCHAR( 50 ) NULL DEFAULT NULL ,
						`statusdesc` VARCHAR( 100 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `statusid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_module_admin
			if($number == 7)
			{
				$table = "ms_module_admin";
				if(!(table_exists($table, DB_NAME)))	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`moduleadminid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`moduleadminname` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`moduleadminlabel` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`moduleadminurlback` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`moduleadminposition` INT( 11 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `moduleadminid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check module modules at Table ms_module_admin
				$module_id = 1;
				$module_name = "modules";
				
				$sql = "select * from ms_module_admin where moduleadminname = '".$module_name."' and moduleadminid = '".$module_id."' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_admin` (
						`moduleadminid` ,
						`moduleadminname` ,
						`moduleadminlabel` ,
						`moduleadminurlback` ,
						`moduleadminposition` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup`,
						`stsrc`
						)
						VALUES (
						'".$module_id."',  '".$module_name."',  '".$module_name."', '".strtolower(str_replace(" ","",$module_name)).".php', '".$module_id."',  '1', '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check module usergroup at Table ms_module_admin
				$module_id = 2;
				$module_name = "user group";
				
				$sql = "select * from ms_module_admin where moduleadminname = '".$module_name."' and moduleadminid = '".$module_id."' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_admin` (
						`moduleadminid` ,
						`moduleadminname` ,
						`moduleadminlabel` ,
						`moduleadminurlback` ,
						`moduleadminposition` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup`,
						`stsrc`
						)
						VALUES (
						'".$module_id."',  '".$module_name."',  '".$module_name."', '".strtolower(str_replace(" ","",$module_name)).".php', '".$module_id."',  '1', '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check module history at Table ms_module_admin
				$module_id = 3;
				$module_name = "module privilege";
				
				$sql = "select * from ms_module_admin where moduleadminname = '".$module_name."' and moduleadminid = '".$module_id."' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_admin` (
						`moduleadminid` ,
						`moduleadminname` ,
						`moduleadminlabel` ,
						`moduleadminurlback` ,
						`moduleadminposition` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup`,
						`stsrc`
						)
						VALUES (
						'".$module_id."',  '".$module_name."',  '".$module_name."', '".strtolower(str_replace(" ","",$module_name)).".php', '".$module_id."',  '1', '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check module module privilege at Table ms_module_admin
				$module_id = 4;
				$module_name = "history";
				
				$sql = "select * from ms_module_admin where moduleadminname = '".$module_name."' and moduleadminid = '".$module_id."' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_admin` (
						`moduleadminid` ,
						`moduleadminname` ,
						`moduleadminlabel` ,
						`moduleadminurlback` ,
						`moduleadminposition` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup`,
						`stsrc`
						)
						VALUES (
						'".$module_id."',  '".$module_name."',  '".$module_name."', '".strtolower(str_replace(" ","",$module_name)).".php', '".$module_id."',  '1', '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_user_group
			if($number == 8)
			{
				$table = "ms_user_group";
				if(!(table_exists($table, DB_NAME)))	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`usergroupid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`usergroupname` VARCHAR( 50 ) NULL DEFAULT NULL ,
						`usergroupstatus` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `usergroupid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check user group for masteradmin (developer)
				$sql = "select * from ms_user_group where usergroupid = '1' and usergroupname = 'developer' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						
						INSERT INTO  `".DB_NAME."`.`ms_user_group` (
						`usergroupid` ,
						`usergroupname` ,
						`usergroupstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'1',  'developer',  '1', '1', '',  '".GET_DATE."',  '',  'A'
						);
						
						
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				
				// Check user group for superadmin (owner)
				$sql = "select * from ms_user_group where usergroupid = '2' and usergroupname = 'owner' ";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						
						INSERT INTO  `".DB_NAME."`.`ms_user_group` (
						`usergroupid` ,
						`usergroupname` ,
						`usergroupstatus` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'2',  'owner',  '1', '1', '',  '".GET_DATE."',  '',  'A'
						);
						
						
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table tr_login_punishment
			if($number == 9)
			{
				$table = "tr_login_punishment";
				if(!(table_exists($table, DB_NAME)))	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`loginpunishmentid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`loginpunishmentip` VARCHAR( 15 ) NULL DEFAULT NULL ,
						`loginpunishmentcount` TINYINT( 1 ) NULL DEFAULT NULL ,
						`loginpunishmentstatus` TINYINT( 1 ) NULL DEFAULT NULL ,
						`loginpunishmentrelease` DATETIME NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						PRIMARY KEY (  `loginpunishmentid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_module_group_privilege
			if($number == 10)
			{
				$table = "ms_module_group_privilege";
				if(!(table_exists($table, DB_NAME)))	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`modulegroupprivilegeid` INT( 11 ) NOT NULL AUTO_INCREMENT,
						`modulegroupprivilegetype` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`usergroupid` INT( 11 ) NULL DEFAULT NULL ,
						`modulegroupprivilegemoduleid` INT( 11 ) NULL DEFAULT NULL ,
						`modulegroupprivilegemodulesubid` INT( 11 ) NULL DEFAULT NULL ,
						`modulegroupprivilegeenable` TINYINT( 1 ) NULL DEFAULT NULL ,
						`modulegroupprivilegeinsert` TINYINT( 1 ) NULL DEFAULT NULL ,
						`modulegroupprivilegeupdate` TINYINT( 1 ) NULL DEFAULT NULL ,
						`modulegroupprivilegedelete` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `modulegroupprivilegeid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			
			// Check Table ms_module_sub_2
			if($number == 11)
			{
				/*
				$table = "ms_module_sub_2";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`modulesub2id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`modulesubid` INT( 11 ) NULL DEFAULT NULL ,
						`modulesub2name` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulesub2label` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulesub2urltype` VARCHAR( 30 ) NULL DEFAULT NULL ,
						`modulesub2urlfront` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`modulesub2urlback` VARCHAR( 200 ) NULL DEFAULT NULL ,
						`modulesub2position` INT( 11 ) NULL DEFAULT NULL ,
						`modulesub2status` TINYINT( 1 ) NULL DEFAULT NULL ,
						`userin` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`userup` VARCHAR( 20 ) NULL DEFAULT NULL ,
						`datein` DATETIME NULL DEFAULT NULL ,
						`dateup` DATETIME NULL DEFAULT NULL ,
						`stsrc` VARCHAR( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `modulesub2id` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
				*/
				/*
				// check submodule2 record 'submodules2'
				$sql = "select * from ms_module_sub_2 where modulesub2name = 'submodules 2'";
				$exe = mysql_query($sql) or die(mysql_error());
				$num = mysql_num_rows($exe);
				
				if($num <= 0)	// create record if not exists
				{
					$sql = " 	
						INSERT INTO  `".DB_NAME."`.`ms_module_sub_2` (
						`modulesub2id` ,
						`modulesubid` ,
						`modulesub2name` ,
						`modulesub2label` ,
						`modulesub2urltype` ,
						`modulesub2urlfront` ,
						`modulesub2urlback` ,
						`modulesub2position` ,
						`modulesub2status` ,
						`userin` ,
						`userup` ,
						`datein` ,
						`dateup` ,
						`stsrc`
						)
						VALUES (
						'1',  '1',  'submodules 2',  'sub modules 2',  'management',  'submodules2.php',  'submodules2.php',  '1',  '1',  '1',  '',  '".GET_DATE."',  '',  'A'
						);
					";
					$exe = mysql_query($sql) or die(mysql_error());
				}
				*/
			}
			
			// Check Table ms_image
			if($number == 12)
			{
				$table = "ms_image";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`imageid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						`fileid` INT( 11 ) NULL DEFAULT NULL ,
						`imagewidth` INT( 11 ) NULL DEFAULT NULL ,
						`imageheight` INT( 11 ) NULL DEFAULT NULL ,
						PRIMARY KEY (  `imageid` )
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			// Check Table ms_component
			if($number == 13)
			{
				$table = "ms_component";
				if(!(table_exists($table, DB_NAME))) 	// create table if not exists
				{
					$sql = " 	
						CREATE TABLE  `".DB_NAME."`.`".$table."` (
						`componentid` int( 11 ) NOT NULL AUTO_INCREMENT ,
						`componentname` varchar( 100 ) NULL DEFAULT NULL ,
						`componentlabel` varchar( 100 ) NULL DEFAULT NULL ,
						`componentrole` varchar( 30 ) NULL DEFAULT NULL ,
						`componentversion` varchar( 100 ) NULL DEFAULT NULL ,
						`componentauthor` varchar( 100 ) NULL DEFAULT NULL ,
						`componentposition` int( 11 ) NULL DEFAULT NULL ,
						`componentstatus` tinyint( 4 ) NULL DEFAULT NULL ,
						`userin` varchar( 20 ) NULL DEFAULT NULL ,
						`userup` varchar( 20 ) NULL DEFAULT NULL ,
						`datein` datetime NULL DEFAULT NULL ,
						`dateup` datetime NULL DEFAULT NULL ,
						`stsrc` varchar( 1 ) NULL DEFAULT NULL ,
						PRIMARY KEY ( `componentid` ) 
						) ENGINE = INNODB ;
					";
					$exe = mysql_query($sql) or die(mysql_error());
					$result = 1;
				}
			}
			
			/*

			*/
			
			return $result;
		}
	}
?>